package com.dfdchem.imd.kaiwu.util;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.CountDownTimer;
import android.widget.Button;

import com.dfdchem.imd.kaiwu.R;

public class CountDownTimerUtils extends CountDownTimer {
    private Button mButton;
    private Context mContext;


    public CountDownTimerUtils(Context context, Button button, long second) {
        super(second * 1000, 1000);
        this.mButton = button;
        this.mContext = context;
    }

    @Override
    public void onTick(long millisUntilFinished) {
        mButton.setClickable(false); //设置不可点击
        mButton.setEnabled(false);
        mButton.setText(millisUntilFinished / 1000 + "秒");  //设置倒计时时间
    }

    @SuppressLint("ResourceAsColor")
    @Override
    public void onFinish() {
        mButton.setText("重新获取");
        mButton.setClickable(true);//重新获得点击
        mButton.setEnabled(true);
        mButton.setBackground(mContext.getResources().getDrawable(R.drawable.login_button_selector));
    }
}
